﻿/*
*	for count FPS
*/
#include "ChaosFramePerSecond.hpp"
namespace Chaos
{
	int			ChsFramePerSecond::ms_nLastTime			= ::GetTickCount();
	int			ChsFramePerSecond::ms_nCnt				= 0;
	int			ChsFramePerSecond::ms_nAveCnt			= 0;
	int			ChsFramePerSecond::ms_nSecondTime		= 0;
	float		ChsFramePerSecond::ms_fCurFps			= 0;
	float		ChsFramePerSecond::ms_fAveFps			= 0;
	float		ChsFramePerSecond::ms_fTotalFps			= 0;
	float		ChsFramePerSecond::ms_fMaxFps			= 0;


	void ChsFramePerSecond::Update()
	{
		++ms_nCnt;
		
		int nowTime = ::GetTickCount();

		if(nowTime - ms_nLastTime >= 200)
		{
			ms_fCurFps = 1000.0f * ms_nCnt / ( nowTime - ms_nLastTime );
			ms_fMaxFps = ms_fCurFps > ms_fMaxFps ? ms_fCurFps : ms_fMaxFps;
			ms_nLastTime = nowTime;
			ms_nCnt=0;
			ms_fTotalFps+=ms_fCurFps;
			++ms_nAveCnt;
		}

		if(nowTime - ms_nSecondTime>=1000)
		{
			ms_fAveFps = ms_fTotalFps/ms_nAveCnt;
			ms_nAveCnt=0;
			ms_fTotalFps=0;
			ms_nSecondTime = ::GetTickCount();
		}
	}

}//namespace Chaos

